/*******************************************************************************
*
*   FILE NAME:
*       GraphicsDeviceManager.cpp - GraphicsDeviceManager class implementation
*
*   DESCRIPTION:
*       Handles the configuration and management of the graphics device.
*
*******************************************************************************/
#include "GraphicsDeviceManager.h"

GraphicsDeviceManager::GraphicsDeviceManager( Game& game )
    : mGraphicsDevice( game.GetGraphicsDevice() ),
      mPresentationParameters( game.GetGraphicsDevice().GetPresentationParameters() )
{
}

GraphicsDeviceManager::~GraphicsDeviceManager( void )
{
}

void GraphicsDeviceManager::ApplyChanges( void )
{
    mGraphicsDevice.Reset( mPresentationParameters );
}

GraphicsDevice& GraphicsDeviceManager::GetGraphicsDevice( void )
{
    return mGraphicsDevice;
}

boolean GraphicsDeviceManager::IsMultiSamplingPreferred( void )
{
    return ( mPresentationParameters.MultiSampleCount > 0 );
}

SurfaceFormat GraphicsDeviceManager::GetPreferredBackBufferFormat( void )
{
    return mPresentationParameters.BackBufferFormat;
}

uint32 GraphicsDeviceManager::GetPreferredBackBufferHeight( void )
{
    return mPresentationParameters.BackBufferHeight;
}

uint32 GraphicsDeviceManager::GetPreferredBackBufferWidth( void )
{
    return mPresentationParameters.BackBufferWidth;
}

DepthFormat GraphicsDeviceManager::GetPreferredDepthStencilFormat( void )
{
    return mPresentationParameters.DepthStencilFormat;
}

boolean GraphicsDeviceManager::IsFullScreen( void )
{
    return mPresentationParameters.IsFullScreen;
}

boolean GraphicsDeviceManager::IsSynchronizedWithVerticalRetrace( void )
{
    return ( mPresentationParameters.PresentationInterval == PRESENT_INTERVAL_ONE );
}

void GraphicsDeviceManager::SetFullScreen( boolean fullscreen )
{
    mPresentationParameters.IsFullScreen = fullscreen;
}

void GraphicsDeviceManager::SetPreferMultiSampling( boolean prefer_multisampling )
{
    mPresentationParameters.MultiSampleCount = ( prefer_multisampling == TRUE ) ? 4 : 0;
}

void GraphicsDeviceManager::SetPreferredBackBufferFormat( SurfaceFormat preferred_back_buffer_format )
{
    mPresentationParameters.BackBufferFormat = preferred_back_buffer_format;
}

void GraphicsDeviceManager::SetPreferredBackBufferHeight( uint32 preferred_back_buffer_height )
{
    mPresentationParameters.BackBufferHeight = preferred_back_buffer_height;
}

void GraphicsDeviceManager::SetPreferredBackBufferWidth( uint32 preferred_back_buffer_width )
{
    mPresentationParameters.BackBufferWidth = preferred_back_buffer_width;
}

void GraphicsDeviceManager::SetPreferredDepthStencilFormat( DepthFormat preferred_depth_stencil_format )
{
    mPresentationParameters.DepthStencilFormat = preferred_depth_stencil_format;
}

void GraphicsDeviceManager::SetSynchronizeWithVerticalRetrace( boolean vsync )
{
    mPresentationParameters.PresentationInterval = ( vsync == TRUE ) ? PRESENT_INTERVAL_ONE : PRESENT_INTERVAL_IMMEDIATE;
}
